package com.atguigu.tingshu.order.mq;

import com.alibaba.cloud.commons.lang.StringUtils;
import com.atguigu.tingshu.common.constant.KafkaConstant;
import com.atguigu.tingshu.order.service.OrderInfoService;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

/**
 * Author  王东剑
 * Created on 25/6/2024 PM8:04
 * Package_name com.atguigu.tingshu.order.mq
 * Description
 */
@Component
@Slf4j
public class OrderReceiver {
	@Autowired
	private OrderInfoService orderInfoService;
	@KafkaListener(topics = KafkaConstant.QUEUE_ORDER_PAY_SUCCESS)
	public void processPayedOrder(ConsumerRecord<String,String> record){
		String orderNo = record.value();
		if(!StringUtils.isEmpty(orderNo)){
			orderInfoService.orderPaySuccess(orderNo);
			log.info("更改订单的支付状态以及保存购买信息成功了.......orderNo: {}",orderNo);
		}
	}
}
